package com.uchedao.seller.ui.baidu;

import com.android.volley.Request;
import com.android.volley.RequestQueue;
import com.baidu.mobstat.StatService;
import com.uchedao.ulibrary.fragment.BaseFragmentActivity;
import com.uchedao.ulibrary.fragment.FragmentMrg;

/**
 * 百度移动统计－－Activity
 * Created by zhengxizhen on 15/10/13.
 */
public abstract class BaseActForBaidu extends BaseFragmentActivity {

    /**
     * 页面标签
     */
    protected String TAG = "BaseActForBaidu";
    /**
     * 网络请求队列
     */
    protected RequestQueue mQueue;

    /**
     * 获取标签
     */
    public abstract String getTAGName();

    @Override
    public abstract void initFragment();

    @Override
    public abstract boolean isProgressDialogShowing();

    @Override
    public abstract void showProgressDialog(String s);

    @Override
    public abstract void cancelProgressDialog();

    /**
     * 网络请求添加到请求队列中
     */
    public void addQueue(Request queue) {
        //设置标签
        queue.setTag(TAG);
        if (mQueue != null) {
            mQueue.add(queue);
        }
    }

    @Override
    protected void onPause() {
        super.onPause();
        StatService.onPageEnd(this, TAG);
        //取消当前页面所有的网络请求
        if (mQueue != null) {
            mQueue.cancelAll(TAG);
        }
    }

    @Override
    protected void onResume() {
        super.onResume();
        StatService.onPageStart(this, TAG);
    }

    @Override
    public void onBackPressed() {
        if (!FragmentMrg.onKeyBack(this)) {
            this.finish();
            super.onBackPressed();
        }
    }
}
